//
//  RouterServiceProtocol.swift
//  
//
//  Created by tank on 2021/11/17.
//

import Foundation
import LibUI

public enum RouteResult: Int {
    // push success
    case success
    // push error
    case error
    // redirect to login
    case redirectToLogin
}

public protocol RouterServiceProtocol: AnyObject {
    typealias RouteCompletion = (_ result: RouteResult, _ param: Any?) -> Void
    
    var urls: [String] { get }
    
    func openDeepLink(url: String, params: [String: Any]?, completion: RouteCompletion?)
    
    func open(url: String, params: [String: Any]?, completion: RouteCompletion?)
    
    func push(url: String, animated: Bool)
    
    func push(url: String,
              params: [String: Any]?,
              animated: Bool,
              completion: RouteCompletion?)
    
    func push(urlComponents: URLComponents,
              params: [String: Any]?,
              animated: Bool,
              completion: RouteCompletion?)
    
    func pop(animated: Bool) -> Bool
    
    func pop(value: Any?, animated: Bool) -> Bool
    
    /// 关闭当前页面，返回上一页面或多级页面
    /// - Parameters:
    ///   - delta: 返回的页面数，如果 delta 大于现有页面数，则返回到首页。
    ///   - value: 返回结果
    ///   - animated: 支持返回动效
    /// - Returns: reslut
    func pop(delta: Int, value: Any?, animated: Bool) -> Bool
    
    /// 关闭指定页面
    /// - Parameter urls: 页面列表
    func finish(urls: [String])
    
    func present(url: String, animated: Bool)
    
    func present(url: String,
                 params: [String: Any]?,
                 animated: Bool,
                 completion: RouteCompletion?)
    
    func present(urlComponents: URLComponents,
                 params: [String: Any]?,
                 animated: Bool,
                 completion: RouteCompletion?)
    
    func dismiss(animated: Bool) -> Bool
    
    func dismiss(value: Any?, animated: Bool) -> Bool
    
    func handle(url: String,
                params: [String: Any]?,
                completion: RouteCompletion?)
    
    func handle(urlComponents: URLComponents,
                params: [String: Any]?,
                completion: RouteCompletion?)
    
    func alert(title: String?, message: String)
    
    func alert(dialogId: String?, title: String?, message: String,
               confirmButtonText: String?, interactive: Bool,
               completion: Dialog.DialogCompletion?)
    
    func confirm(title: String?, message: String)
    
    func confirm(dialogId: String?, title: String?, message: String,
                 confirmButtonText: String?, cancelButtonText: String?,
                 interactive: Bool, completion: Dialog.DialogCompletion?)
    
    func toast(message: String, interactive: Bool, duration: TimeInterval,
                 completion: Toast.ToastCompletion?)
    
    func loading(message: String, interactive: Bool,
                 completion: Toast.ToastCompletion?)
    
    func closeToast()
}
